import AbstractService from "./abstract.service";

export class UserService extends AbstractService {
  /**
   * 用户登录
   * @param data
   */
  login(data: any) {
    return super.PostData("api/user/v1/login", data);
  }

  /**
   * 用户注册
   * @param data
   */
  register(data: any) {
    return super.PostData("api/user/v1/register", data);
  }

  /**
   *用户详情
   */
  detail() {
    return super.GetData("api/user/v1/detail");
  }

  /**
   * 修改用户信息
   */
  updateUserInfo(data: any) {
    return super.PostData("api/user/v1/update", data);
  }
  /**
   * 修改用户信息
   */
  recharge(amount: number) {
    return super.PostData("api/user/v1/recharge", { amount });
  }

  /**
   * 用户头像上传
   */
  upload(data: any) {
    return super.PostData("api/user/v1/upload", { file: data });
  }

  /**
   * 获取验证码
   */
  getCaptcha() {
    return Promise.resolve(super.getBaseServerUrl() + "api/user/v1/getCaptcha");
  }

  /**
   * 验证码校验
   */
  confirmCaptcha(data: any) {
    return super.GetData("api/user/v1/confirmCaptcha");
  }

  /**
   *  余额记录列表
   */
  records() {
    return super.GetData("api/user/v1/records");
  }
  /**
   *  地址列表
   */
  addressList() {
    return super.GetData("api/user/v1/address/");
  }

  /**
   *  地址详情
   */
  addressDetail(id: string) {
    return super.GetData(`api/user/v1/address/${id}`);
  }

  /**
   *  新增地址
   */
  addAddress(data: { detailAddress: string; receiveName: string; phone: string }) {
    const reqData = {
      city: "",
      defaultStatus: 0,
      province: "",
      region: "",
      ...data,
    };
    return super.PostData(`api/user/v1/address/`, reqData);
  }

  /**
   * 修改地址
   */
  changeAddress(data: any) {
    return super.PutData(`api/user/v1/address/${data.id}`, data);
  }

  /**
   * 删除地址
   */
  deleteAddress(id: string) {
    return super.DeleteData(`api/user/v1/address/${id}`);
  }
}
